package com.caoji.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.caoji.entity.CategoryDto;
import com.caoji.item.entity.Category;
import com.caoji.item.mapper.CategoryMapper;
import com.caoji.item.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description： User: caoji
 * Date: 2020/12/4
 * Time: 11:38
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Override
    public CategoryDto findbyid(Long id) {
        Category category = baseMapper.selectById(id);
        return new CategoryDto(category);
    }

    @Override
    public List<CategoryDto> findbyids(List<Long> ids) {
        return CategoryDto.convertEntityList(listByIds(ids));
    }

    @Override
    public List<CategoryDto> findbyparent(Long pid) {
        List<Category> categories = query().eq("parent_id", pid).list();
        return CategoryDto.convertEntityList(categories);
    }

    @Override
    public List<CategoryDto> findbybandis(Long id) {
        List<Long> cateids = baseMapper.findbybandis(id);
        return findbyids(cateids);
    }
}